/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import static javax.persistence.TemporalType.TIMESTAMP;

/**
 *
 * @author Yeezus
 */
@Entity
@Table(name = "ENCOMENDA")
@NamedQueries({
    @NamedQuery(name = "findAllEncomendas",
    query = "SELECT enc FROM Encomenda enc " + " WHERE enc.farmacia.nome = :nome"
    )})
public class Encomenda implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    
    @Temporal(TIMESTAMP)
    private Date dataEncomenda;

    private boolean isFechada = false;
    
    @OneToMany(mappedBy = "encomenda", cascade = CascadeType.REMOVE)
    private List<LinhaEncomenda> linhaEncomendas;

    @ManyToOne
    @JoinColumn(name = "ADMIN_ID")
    private Administrador admin;
    
    @ManyToOne
    @JoinColumn(name = "FARMACIA_ID")
    private Farmacia farmacia;

    private static DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    public Encomenda() {
        this.linhaEncomendas = new LinkedList<>();
    }

    public Encomenda(boolean isFechada,Administrador administador, Farmacia farmacia) {
        this.dataEncomenda = new Date();
        this.isFechada=isFechada;
        this.admin=administador;
        this.farmacia=farmacia;
        this.linhaEncomendas = new LinkedList<>();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<LinhaEncomenda> getEncomendas() {
        return linhaEncomendas;
    }

    public void setEncomendas(List<LinhaEncomenda> encomendas) {
        this.linhaEncomendas = encomendas;
    }

    public boolean isIsFechada() {
        return isFechada;
    }

    public void setIsFechada(boolean isFechada) {
        this.isFechada = isFechada;
    }

    public List<LinhaEncomenda> getLinhasEncomenda() {
        return linhaEncomendas;
    }

    public void setLinhasEncomenda(List<LinhaEncomenda> linhasEncomenda) {
        this.linhaEncomendas = linhasEncomenda;
    }

    public Administrador getAdmin() {
        return admin;
    }

    public void setAdmin(Administrador admin) {
        this.admin = admin;
    }

    public Date getDataEncomenda() {
        return dataEncomenda;
    }

    public void setDataEncomenda(Date dataEncomenda) {
        this.dataEncomenda = dataEncomenda;
    }

    public Farmacia getFarmacia() {
        return farmacia;
    }

    public void setFarmacia(Farmacia farmacia) {
        this.farmacia = farmacia;
    }
    public void fecharEncomenda(){
        this.isFechada=true;
    }
}
